#!/usr/bin/env bash

ServerName=$1

PackagePath=$2

PackageName=$3

cd /userdata1/tanbao2

rm -rf ${PackageName}*

cp ${PackagePath}/${PackageName}.tar.gz .

tar -xzf ${PackageName}.tar.gz

rm -rf ${PackageName}.tar.gz

#cp 原服务器下的日志
mv ${ServerName}/*.log  ${PackageName}/

rm -rf ${ServerName}

mv ${PackageName} ${ServerName}

cd ${ServerName}/

#nohup ./${ServerName} &

ps -ef | grep ${ServerName} |grep -v grep|grep -v pkg-sources
#停止之前的进程

kill $(ps -ef | grep ${ServerName} |grep -v grep | grep -v pkg-sources | awk '{print $2}')

cur_dateTime=`date +%Y_%m_%d`

nohup ./${ServerName}  -a ./config/config.yml > ${cur_dateTime}.log 2>&1 &

sleep 5

ps -ef | grep ${ServerName} |grep -v grep | grep -v pkg-sources

#
#check_results=`supervisorctl status`
#
#echo ${check_results}